package com.example.mybatis1.mapper;

import com.example.mybatis1.model.UserInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * ClassName: UserInfo2Mapper
 * Package: IntelliJ IDEA
 * Description:
 *
 * @Author 谷京京
 * @Create 2023/11/17 19:31
 * @Version 1.0
 */
@Mapper
public interface UserInfo2Mapper {
    @Insert("<script>" +
            "insert into userinfo (username, password, age, " +
            "<if test = 'gender!=null' >gender,</if> " +
            "phone)" +
            " values(#{username}, #{password}, #{age}, " +
            "<if test = 'gender!=null' >#{gender}, </if>" +
            "#{phone})" +
            "</script>")
    Integer insert(UserInfo userInfo);
    Integer insertByXML(UserInfo userInfo);

    /**
     * 使用where标签
     * @param userInfo
     * @return
     */
    List<UserInfo> selectByCondition(UserInfo userInfo);

    /**
     * 使用trim标签
     * @param userInfo
     * @return
     */
    List<UserInfo> selectByCondition2(UserInfo userInfo);

    /**
     * 使用注解
     * @param userInfo
     * @return
     */
    @Select("<script>" +
            "select * from userinfo" +
            "        <where>" +
            "            <if test=\"username!=null\">" +
            "                username = #{username}" +
            "            </if>" +
            "            <if test=\"age!=null\">" +
            "                or age = #{age}" +
            "            </if>" +
            "            <if test=\"gender!=null\">" +
            "                and gender = #{gender}" +
            "            </if>" +
            "        </where>"+
            "</script>")
    List<UserInfo> selectByCondition3(UserInfo userInfo);

    /**
     * 使用trim标签
     * @param userInfo
     * @return
     */
    Integer updateByCondition(UserInfo userInfo);

    /**
     * 使用set标签
     * @param userInfo
     * @return
     */
    Integer updateByCondition2(UserInfo userInfo);
    Integer batchDelete(List<Integer> ids);
}
